package utils.json.serializer;

import java.lang.reflect.Type;

import models.Article;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

/**
 * @author ultrafrog
 * @version 1.0, 2014-12-01
 * @since 1.0
 */
public class ArticleSerializer implements JsonSerializer<Article> {

	/* (non-Javadoc)
	 * @see com.google.gson.JsonSerializer#serialize(java.lang.Object, java.lang.reflect.Type, com.google.gson.JsonSerializationContext)
	 */
	@Override
	public JsonElement serialize(Article val, Type type, JsonSerializationContext ctx) {
		JsonObject obj = new JsonObject();
		obj.addProperty("id", val.id);
		obj.addProperty("title", val.title);
		obj.addProperty("author", val.author);
		obj.addProperty("description", val.description);
		obj.addProperty("picUrl", val.picUrl);
		obj.addProperty("text", val.text);
		obj.addProperty("datetime", val.datetime.getTime());
		return obj;
	}
}
